﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace ScoutNET.Helpers
{
    public static class HourFieldsdHelper
    {
        public static string HourFields(this HtmlHelper htmlHelper, string hourFieldName, string minuteFieldName)
        {
            return HourFields(htmlHelper, hourFieldName, minuteFieldName, -1 ,-1, null);
        }

        public static string HourFields(this HtmlHelper htmlHelper, string hourFieldName, string minuteFieldName, object htmlAttributes)
        {
            return HourFields(htmlHelper, hourFieldName, minuteFieldName, -1, -1, htmlAttributes);
        }

        public static string HourFields(this HtmlHelper htmlHelper, string hourFieldName, string minuteFieldName, int hourValue, int minuteValue)
        {
            return HourFields(htmlHelper, hourFieldName, minuteFieldName, hourValue, minuteValue, null);
        }

        public static string HourFields(this HtmlHelper htmlHelper, string hourFieldName, string minuteFieldName, int hourValue, int minuteValue, object htmlAttributes)
        {
            Dictionary<string, string> hour = new Dictionary<string, string>();
            hour.Add("","");
            for (int i = 0; i <= 23; i++)
            {
                hour.Add(i.ToString(), i.ToString("00"));
            }
            SelectList slStartHour = new SelectList(hour, "Key", "Value", hourValue);


            Dictionary<string, string> minute = new Dictionary<string, string>();
            minute.Add("", "");
            for (int i = 0; i <= 45; i = i + 15)
            {
                minute.Add(i.ToString(), i.ToString("D2"));
            }
            SelectList slStartMinutes = new SelectList(minute, "Key", "Value", minuteValue);

            string attributes = string.Empty;
            if (htmlAttributes != null)
            {
                IDictionary<string, object> dAttributes = new RouteValueDictionary(htmlAttributes);
                if (dAttributes != null)
                {
                    foreach (var item in dAttributes)
                    {
                        attributes += item.Key + "=\"" + item.Value + "\"";
                    }
                }
            }

            return "<span "+ attributes + ">" + htmlHelper.DropDownList(hourFieldName, slStartHour, htmlAttributes) + " : " + htmlHelper.DropDownList(minuteFieldName, slStartMinutes) + "</span>";
        }
    }
}